


create proc GiaoDichNapTien(@MaloaiGD char(6), @MaNV char(10), @MaTK char(13), @CNhanhGD int, @hotennggui nvarchar(50), @diachinggui nvarchar(50), @NgHangNhan int, @sotien money)
as
begin tran
	-- kiem tra MaTK ton tai
	if exists(select * from Tai_Khoan where MaTK = @MaTK) begin
		declare @MaGD int
		set @MaGD = ((select count(*) from Giao_Dich) + 1)
		declare @phi money
		set @phi = 100
		insert into Giao_Dich values (@maGD, GetDate(),@MaloaiGD, @MaNV, @maTK,@phi, @CNhanhGD)
		-- kiem tra thao tac insert co thanh cong hay ko?
		if(@@error <> 0) begin
			rollback tran
			return 0
		end

		declare @MaPhieu int
		set @MaPhieu = ((select count(*) from Phieu_Nap_Tien) + 1)
		insert into Phieu_Nap_Tien values (@maPhieu, @MaGD, @hotennggui,@diachinggui,@NgHangNhan,@sotien )
		-- kiem tra thao tac insert co thanh cong hay ko?
		if(@@error <> 0) begin
			rollback tran
			return 0
		end

		-- xu ly cho tai khoan ....
	end
	else begin
		rollback tran
		return 0
	end

commit